package com.cml.dm.admin.service.sql;

import com.cml.dm.admin.entity.DmExeLogger;
import com.cml.dm.admin.entity.DmMetadata;
import com.cml.dm.admin.service.RecoverySqlGenerateService;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class DefaultDeleteRecoverySqlGenerateService implements RecoverySqlGenerateService {
    /**
     * extParameter 传入备份的所有id，以逗号分隔
     * @param dmMetadata
     * @param dmExeLogger
     * @param extParameter
     * @return
     */
    @Override
    public List<String> sqlGenerate(DmMetadata dmMetadata, DmExeLogger dmExeLogger, Object extParameter) {
        List<String> sqlList = new ArrayList<>();
        String sf = "delete from %s where %s=%s and %s in (%s)";
//        String sql ="delete from "+dmMetadata.getTable() +" where " + dmMetadata.getOrgId() +"="+dmExeLogger.getOrgId();
//        sql += " and " + dmMetadata.getPk() + " not in (" + extParameter +")";
        String sql = String.format(sf,dmMetadata.getTable(),dmMetadata.getOrgId(),dmExeLogger.getOrgId(),dmMetadata.getPk(),extParameter);
        sqlList.add(sql);
        return sqlList;
    }
}
